package itbour.onetouchshow.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import itbour.onetouchshow.R;
import itbour.onetouchshow.adapter.base.BaseAdapterHelper;
import itbour.onetouchshow.adapter.base.normal.QuickAdapter;
import itbour.onetouchshow.bean.HomeClassifyBean;

/**
 * Created by Yang on 2018/2/28.
 */

public class HomeClassifyAdapter extends QuickAdapter<HomeClassifyBean> {

    public static final int maxItemCount = 8;

    public HomeClassifyAdapter(Context context) {
        super(context, R.layout.item_home_classify);
    }

    @Override
    public int getCount() {
        if (data.size() <= maxItemCount) return super.getCount();
        else {
            return maxItemCount;
        }
    }

    @Override
    protected void convert(BaseAdapterHelper helper, HomeClassifyBean item, int position) {
        helper.setText(R.id.tv_classify_name, item.getName());
        Glide.with(context).setDefaultRequestOptions(new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
                .error(R.drawable.icon_classify_place)
                .placeholder(R.drawable.icon_classify_place)).load(item.getIcon()).into((ImageView) helper.getView(R.id.iv_classify_im));
        if (getData().size() > maxItemCount && position == maxItemCount - 1) {
            helper.setText(R.id.tv_classify_name, "更多");
        }
    }


}
